package com.atguigu.day16.work;

import java.util.Arrays;

public class Work5 {
    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,6,7};
        arr=changPosition(1,4,arr);
        System.out.println(Arrays.toString(arr));
    }
    public static int[] changPosition(int n1,int n2,int[] ii){
        int indexN1=1;
        for (int i = 0; i < ii.length; i++) {
            if (ii[i]==n1) {
                indexN1=i;
                break;
            }
        }
        int indexN2=-1;
        for (int i = 0; i < ii.length; i++) {
            if (ii[i]==n2) {
                indexN2=i;
                break;
            }
        }
        System.arraycopy(ii,indexN1+1,ii,indexN1,indexN2-indexN1);
        ii[indexN2]=n1;
        return ii;
    }
}
